package com.wwdx.controller.admin;

import com.wwdx.controller.base.BaseController;
import com.wwdx.model.WwdxCouponModel;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.Date;

/**
 * @author liguoliang
 * @date 2018/4/20 13:16
 */
@Controller
@RequestMapping("/system/wwdx_coupon")
public class WwdxCouponController extends BaseController{

    /**
     * 列表
     */
    @RequestMapping("/list")
    public ModelAndView chapterlist(WwdxCouponModel model,
                                    @RequestParam(value = "page", defaultValue = "1") int page,
                                    @RequestParam(value = "rows",defaultValue = "10") int rows) {

        ModelAndView mav = new ModelAndView();
        mav.addObject("listSize", wwdxCouponService.selectModelCount(model));
        mav.addObject("list", wwdxCouponService.selectModelList(model,page,rows));
        return mav;
    }

    /**
     * 新增
     */
    @RequestMapping("/create")
    public ModelAndView create() {
        return new ModelAndView();
    }

    /**
     * 保存新增
     */
    @RequestMapping("/save")
    public String save(WwdxCouponModel model) {
        model.setGmtCreated(new Date());
        model.setGmtModified(new Date());
        wwdxCouponService.save(model);
        return "redirect:/system/wwdx_coupon/list";
    }

    /**
     * 修改页面
     */
    @RequestMapping("/edit")
    public ModelAndView edit(Long id) {
        ModelAndView mav = new ModelAndView();
        mav.addObject("model", wwdxCouponService.getById(id));
        return mav;
    }

    /**
     * 保存修改
     */
    @RequestMapping("/update")
    public String update(WwdxCouponModel model) {
        model.setGmtModified(new Date());
        wwdxCouponService.update(model);
        return "redirect:/system/wwdx_coupon/list";
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresRoles("super")
    public String delete(Long id) {
        wwdxCouponService.delete(wwdxCouponService.getById(id));
        return "redirect:/system/wwdx_coupon/list";
    }
}